package com.suray.attendance.db.service.impl;


import com.suray.attendance.db.mapper.DeptInfoMapper;
import com.suray.attendance.model.pojo.DeptInfo;
import com.suray.attendance.db.service.DingDeptDBService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: jianglinyu
 * @CreateTime: 2023-07-10  13:21
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class DingDeptDBServiceImpl implements DingDeptDBService {

    @Resource
    private DeptInfoMapper deptInfoMapper;

    /**
     * @param deptInfoList
     * @description: 批量新增更新mysql中的部门信息
     * @author: jianglinyu
     * @date: 2023/7/10 14:09
     */
    @Override
    @Transactional(rollbackFor = Exception.class) // TODO: 记得事务管理
    public void insertOrUpdateDingDeptDB(List<DeptInfo> deptInfoList) {
        if(deptInfoList!=null && deptInfoList.size()>0){
            try {
                deptInfoMapper.batchInsert(deptInfoList);
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException("批量新增更新mysql中的部门信息失败");
            }
        }
    }

    /**
     * @param pid
     * @description: 根据pid去数据库里查询其子部门列表
     * @author: jianglinyu
     * @date: 2023/7/10 14:41
     */
    @Override
    public List<Long> getDingDeptByPid(Long pid) {
        List<Long> deptIdList = deptInfoMapper.selectByPid(pid);
        return deptIdList;
    }

    /**
     * @description: 从数据库中查询出所有的deptId
     * @author: jianglinyu
     * @date: 2023/7/11 11:57
     * @return*/
    @Override
    public List<Long> getDeptIdListFromDB() {
        return deptInfoMapper.selectAllIdList();
    }

    @Override
    public List<Map<Long, Long>> getDeptIdListById(List<Long> deptIdList) {
        return deptInfoMapper.selectDeptIdListById(deptIdList);
    }


}